﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace dzs.Web.supply
{
    public partial class ListProject : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                    Bind(user_id);
                }

                //Bind(0);
            }
        }

        private void Bind(int user_id)
        {
            DataSet ds = new Maticsoft.BLL.project().GetList("");

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }
        //设置预竣工日期
        protected void btn_setTime_Click(object sender, EventArgs e)
        {
            string time = this.txt_isComplteTime.Text;

            Maticsoft.BLL.project pm = new Maticsoft.BLL.project ();

            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                CheckBox cbo = this.GridView1.Rows[i].FindControl("cbo_check") as CheckBox;

                if (cbo != null && cbo.Checked)
                {
                    Label lbl = this.GridView1.Rows[i].FindControl("lbl_projectId") as Label;

                    if (!string.IsNullOrEmpty(lbl.Text))
                    {
                        string projectId = lbl.Text;

                        Maticsoft.Model.project p = pm.GetModel(int.Parse(projectId));

                        p.beComplatedTime = DateTime.Parse(time);

                        pm.Update(p);
                    }
                }

            }

            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                Bind(user_id);
            }

            //Bind(0);
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;

            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                Bind(user_id);
            }
        }
    }
}